package org.asiainfo.common.translation.core.impl;

import cn.hutool.core.convert.Convert;
import lombok.AllArgsConstructor;
import org.apache.dubbo.config.annotation.DubboReference;
import org.asiainfo.common.core.utils.StringUtils;
import org.asiainfo.common.translation.annotation.TranslationType;
import org.asiainfo.common.translation.constant.TransConstant;
import org.asiainfo.common.translation.core.TranslationInterface;
import org.asiainfo.system.api.RemoteUserService;

import java.util.List;

/**
 * 用户昵称列表翻译实现
 *
 * @author dotor-ww
 */
@AllArgsConstructor
@TranslationType(type = TransConstant.USER_ID_LIST_TO_NAME)
public class NickNamesTranslationImpl implements TranslationInterface<List<String>> {

    @DubboReference
    private RemoteUserService remoteUserService;

    /**
     * 通过用户ID列表查询用户昵称列表
     *
     * @param key   需要被翻译的键(不为空)
     * @param other 其他参数
     * @return 翻译后的值
     */
    @Override
    public List<String> translation(Object key, String other) {
        String userIdListStr = Convert.toStr(key);
        List<String> userIds = StringUtils.splitList(userIdListStr, ",");
        return remoteUserService.selectNickNameByUserIdList(userIds);
    }
}
